﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgAdmGlobal.aspx.cs" Inherits="EGuayas.Web.Auditoria.admin.Global.pgAdmGlobal" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link  href="~/Resources/css/Style.css"  rel="stylesheet" />
    <!-- Load Ext JS --> 
    <script src="../../../Resources/js/Global.js"></script>

</head>
<body>
    <form runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
    <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Region="North" BodyPadding="6" Header="False" ButtonAlign="Center">
                <Items>
                    <ext:Panel ID="panC1" runat="server" Layout="ColumnLayout" Border="false">
                        <Items>
                            <ext:Panel ID="panC1Col1" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbProvincia" runat="server" FieldLabel="Provincia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoProvincia">
                                                <Model>
                                                    <ext:Model ID="Model1" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbProvincia_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbProvincia}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtCodigo" runat="server" FieldLabel="Código"></ext:TextField>
                                      <ext:DateField 
                                                    ID="dfFechaInicio" 
                                                    Name="FechaInicio"
                                                    runat="server" 
                                                    FieldLabel="Fecha Inicio" 
                                                    Vtype="daterange" 
                                                    EndDateField="dfFechaLimite"
                                                    EnableKeyEvents="true">
                                    </ext:DateField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col2" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbCanton" runat="server" FieldLabel="Cantón" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoCanton">
                                                <Model>
                                                    <ext:Model ID="Model3" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbCanton_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbCanton}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtNombre" runat="server" FieldLabel="Nombre"></ext:TextField>
                                      <ext:DateField 
                                                    ID="dfFechaLimite"
                                                    Name="FechaFin"
                                                    runat="server"                                                   
                                                    FieldLabel="Fecha Fin"
                                                    Vtype="daterange"
                                                    StartDateField="dfFechaInicio"
                                                    EnableKeyEvents="true">
                                    </ext:DateField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col3" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbParroquia" runat="server" FieldLabel="Parroquia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoParroquia">
                                                <Model>
                                                    <ext:Model ID="Model4" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                    </ext:ComboBox>
                                    <ext:ComboBox Editable="false" ID="cbbEstado" runat="server" FieldLabel="Estado" ValueField="Id" DisplayField="Estado">
                                         <Items>
                                                <ext:ListItem Text="Activo" Value="A"></ext:ListItem>
                                                <ext:ListItem Text="Inactivo" Value="I"></ext:ListItem>
                                         </Items>
		                                <Triggers>
			                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
		                                </Triggers>
		                                <Listeners>
			                                <Select Handler="this.getTrigger(0).show();" />
			                                <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
			                                <TriggerClick Handler="if (index == 0) { 
		                                   this.clearValue(); 
		                                   this.getTrigger(0).hide();
	                                   }" />
		                                </Listeners>
	                            </ext:ComboBox>

                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:Panel>
                </Items>
                <Buttons>
                    <ext:Button runat="server" ID="btnBuscarExpedientesLic" Text="Buscar">
                        <DirectEvents>
                            <Click OnEvent="btnBuscarExpedientesLic_Click">
                                <ExtraParams>
                                    <ext:Parameter Name="Codigo" Value="#{txtCodigo}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="Nombre" Value="#{txtNombre}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ProvinciaId" Value="#{cbbProvincia}.getValue()==null?'':#{cbbProvincia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="CantonId" Value="#{cbbCanton}.getValue()==null?'':#{cbbCanton}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ParroquiaId" Value="#{cbbParroquia}.getValue()==null?'':#{cbbParroquia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="Estado" Value="#{cbbEstado}.getValue()==null?'':#{cbbEstado}.getValue()" Mode="Raw"/>
                                      <ext:Parameter Name="FechaDesde" Value="#{dfFechaInicio}.getValue()==null?'':#{dfFechaInicio}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="FechaHasta" Value="#{dfFechaLimite}.getValue()==null?'':#{dfFechaLimite}.getValue()" Mode="Raw"/>
                                </ExtraParams>
                                <EventMask ShowMask="True"></EventMask>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
                
            <ext:GridPanel runat="server" ID="gpnLicencias" Title="Expedientes para Licencias y Certificados Ambientales"
                Region="Center">
                <Store>
                    <ext:Store runat="server" ID="stoExpedienteLic">
                        <Model>
                                <ext:Model runat="server" IDProperty="Id" >
                                    <Fields>
                                        <ext:ModelField Name="Id"/>  
                                        <ext:ModelField Name="ExpedienteId"/>                         
                                        <ext:ModelField Name="Nombre"/>
                                        <ext:ModelField Name="Codigo"/>
                                        <ext:ModelField Name="Descripcion"/>
                                        <ext:ModelField Name="Estado"/>
                                        <ext:ModelField Name="Categoria"/>
                                        <ext:ModelField Name="FechaCreacion" Type="Date" />
                                        <ext:ModelField Name="Provincia"/>
                                        <ext:ModelField Name="Canton"/>
                                        <ext:ModelField Name="Parroquia"/>
                                        <ext:ModelField Name="Direccion"/>                                     
                                        <ext:ModelField Name="Ubicacion"/>
                                    </Fields>
                                </ext:Model>
                        </Model>
                         <AutoLoadParams>   
                             <ext:Parameter Name="ProvinciaId" Mode="Value"></ext:Parameter>
                             <ext:Parameter Name="CantonId" Mode="Value"></ext:Parameter>  
                             <ext:Parameter Name="ParroquiaId" Mode="Value"></ext:Parameter>
                             <ext:Parameter Name="Codigo" Mode="Value"></ext:Parameter> 
                             <ext:Parameter Name="Estado" Mode="Value"></ext:Parameter>                                                        
                        </AutoLoadParams>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:Column  runat="server"  Text="Nombre" Flex="1" DataIndex="Nombre"/>
                        <ext:Column  runat="server"  Text="Código" DataIndex="Codigo" Width="120" />
                        <ext:Column  runat="server"  Text="Descripción" DataIndex ="Descripcion" Width="150"/>
                        <ext:Column  runat="server"  Text="Ubicación"   DataIndex ="Ubicacion" Width="150" />
                        <ext:Column  runat="server"  Text="Dirección"   DataIndex ="Direccion" Width="150" />
                        <ext:DateColumn  runat="server"  Text="Fecha"       DataIndex ="FechaCreacion"   />
                        <ext:CommandColumn runat="server" Width="80" >
                        <Commands>
                            <ext:GridCommand Icon="ApplicationAdd" CommandName="NuevaAud">
                                <ToolTip Text="Nuevo Expediente Auditoria" />
                            </ext:GridCommand>
                            <ext:CommandSeparator />
                        </Commands>  
                            <%--
                            <DirectEvents>
                                <Command OnEvent="gpnLicencias_Command" Success="AppGlobalJs.mostrarVentanaUrl('pgDetalle.aspx?idExpLic='+record.data.Id+'&idExp='+record.data.ExpedienteId,'Expediente');">
                                    <ExtraParams>
                                        <ext:Parameter Name="Id" Value="record.data.Id" Mode="Raw"/>
                                        <ext:Parameter Name="ExpedienteId" Value="record.data.ExpedienteId" Mode="Raw"/>
                                    </ExtraParams>
                                </Command>
                            </DirectEvents>
                          --%>
                         <Listeners>
                                <Command Handler="pgFnAdmin.ShowNuevoExpediente(record);"></Command>
                            </Listeners>
                        </ext:CommandColumn>
                        
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server" StripeRows="true" />                   
                </View>
                 <Features>
                    <ext:GridFilters runat="server" ID="GridFilters1" Local="true"  MenuFilterText="Filtrar por">
                        <Filters>
                            <ext:StringFilter DataIndex="Nombre" EmptyText="Nombre" />
                            <ext:StringFilter DataIndex="Descripcion"  EmptyText="Descripción"/> 
                                <ext:DateFilter DataIndex="FechaCreacion" AfterText="Despues de" BeforeText="Antes de"  OnText="En">
                                <DatePickerOptions runat="server" TodayText="Ahora" />
                            </ext:DateFilter>                                                           
                        </Filters>
                    </ext:GridFilters>
                </Features>
                <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                        <Items>
                            <ext:Label ID="Label1" runat="server" Text="Filas por página:" />
                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                            <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                                <Items>
                                    <ext:ListItem Text="5" />
                                    <ext:ListItem Text="10" />
                                    <ext:ListItem Text="15" />
                                    <ext:ListItem Text="20" />
                                    <ext:ListItem Text="25" />
                                    <ext:ListItem Text="30" />
                                    <ext:ListItem Text="35" />
                                    <ext:ListItem Text="40" />
                                    <ext:ListItem Text="45" />
                                    <ext:ListItem Text="50" />
                                </Items>
                                <SelectedItems>
                                    <ext:ListItem Value="10" />
                                </SelectedItems>
                                <Listeners>
                                    <Select Handler="#{gpnLicencias}.store.pageSize = parseInt(this.getValue(), 10); #{gpnLicencias}.store.load();" />
                                </Listeners>
                            </ext:ComboBox>
                        </Items>
                  
                    </ext:PagingToolbar>
                </BottomBar> 
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
   </form>
     <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var pgFnAdmin = new Object();
            pgFnAdmin.winUrl = null;
            //Cerrar Ventana
            pgFnAdmin.ClosePgAdmGlobal = function () {
                //No es necesario actualizar datos
               /*
                App.direct.BuscarExpedientes({
                    success: function (result) {
                        
                    },
                    eventMask: {
                        showMask: true,
                        minDelay: 500
                    }
                });
                */
            };
            //Abrir ventana Detalle de Nueva Auditoria
            pgFnAdmin.ShowNuevoExpediente = function (record) {
                pgFnAdmin.winUrl = AppGlobalJs.mostrarVentanaUrl('pgDetalle.aspx?idExp=' + record.data.ExpedienteId, 'Auditoria para ' + record.data.Nombre, null);
                pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(); el.destroy(); });

            };
           

        </script>
    </ext:XScript>
</body>
</html>
